package com.rui.study.algorithm.L_Java自动内存管理_GC学习;

import java.util.Arrays;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-02-26 09:48
 **/
public class 内存分配 {

    private static final int _1MB = 1024 * 1024;

    public static void main(String[] args) {
        if (args != null) {
            System.out.println(Arrays.toString(args));
        }
//        testAllocation();
//        testPretenureSizeThreshold();
        testTenuringThreshold();
    }

    /**
     * 启动参数：-XX:+UseSerialGC -XX:+PrintGCDetails -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8
     */
    public static void testAllocation() {
        byte[] o1, o2, o3, o4;
        o1 = new byte[2 * _1MB];
        o2 = new byte[2 * _1MB];
        o3 = new byte[2 * _1MB];
        o4 = new byte[4 * _1MB];
    }

    /**
     * 启动参数：-XX:+UseSerialGC -XX:+PrintGCDetails -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=3145728
     */
    public static void testPretenureSizeThreshold() {
        byte[] o;
        o = new byte[4 * _1MB];
        o[0]++;
    }

    /**
     * 启动参数：-XX:+UseSerialGC -XX:+PrintGCDetails -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8 -XX:+PrintTenuringDistribution -XX:MaxTenuringThreshold=15
     */
    public static void testTenuringThreshold() {

        byte[] o1, o2, o3;
        o1 = new byte[_1MB / 3];
        o2 = new byte[4 * _1MB];
        o3 = new byte[4 * _1MB];
        o3 = null;
        o3 = new byte[4 * _1MB];
    }
}
